package com.chen.servlet;/*
package com.chen.servlet;

import com.chen.entity.FlightEntity;
import com.chen.service.FlightService;
import com.chen.utils.DateUtils;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.Date;

@WebServlet("/updateFlight")
public class UpdateFlightServlet extends HttpServlet {
    private FlightService flightService = new FlightService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String phone = req.getParameter("phone");
        flightService.strIsEmpty(phone, req, resp);

        String idStr = req.getParameter("id");
        if(idStr == null || idStr == ""){
            //跳转到错误页面，客户端传递有误
            req.setAttribute("errorMsg", "id的值为空");
            req.getRequestDispatcher("error.jsp").forward(req, resp);
            return;
        }
        try {
            //获取id
            Integer id = Integer.parseInt(idStr);
            FlightEntity flightEntity = flightService.getByIdFlight(id);
            if(flightEntity == null){
                req.setAttribute("errorMsg", "该id不在数据库中");
                req.getRequestDispatcher("error.jsp").forward(req, resp);
                return;
            }

            req.setAttribute("f", flightEntity);
            req.setAttribute("phone", phone);
            req.getRequestDispatcher("updateFlight.jsp").forward(req, resp);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        try {
            String phone = req.getParameter("phone");
            flightService.strIsEmpty(phone, req, resp);

            String idStr = req.getParameter("id");
            //验证id的值，验证id是否为空
            flightService.strIsEmpty(idStr, req, resp);
            Integer id = Integer.parseInt(idStr);
            */
/*
 * 按逻辑来讲，以下值为空在不应该报错的，但mysql的规则不允许，暂时不清楚为什么
 * *//*

            String flightId = req.getParameter("flightId");
            flightService.strIsEmpty(flightId, req, resp);

            String company = req.getParameter("company");
            flightService.strIsEmpty(company, req, resp);

            String departureAirport = req.getParameter("departureAirport");
            flightService.strIsEmpty(departureAirport, req, resp);

            String arriveAirport = req.getParameter("arriveAirport");
            flightService.strIsEmpty(arriveAirport, req, resp);

            //将String转化为Data
            String departureTimeStr = req.getParameter("departureTime");
            flightService.strIsEmpty(departureTimeStr, req, resp);
            Date departureTime = DateUtils.stringToDate(departureTimeStr);

            String arriveTimeStr = req.getParameter("arriveTime");
            flightService.strIsEmpty(arriveTimeStr, req, resp);
            Date arriveTime = DateUtils.stringToDate(arriveTimeStr);

            String model = req.getParameter("model");
            flightService.strIsEmpty(model, req, resp);

            String costStr = req.getParameter("cost");
            flightService.strIsEmpty(costStr, req, resp);
            Float cost = Float.parseFloat(costStr);

            //将修改的值置入实体中
            FlightEntity flightEntity = flightService.setEntity(id, flightId,
                    company, departureAirport, arriveAirport,
                    departureTime, arriveTime, model, cost);
            int result = flightService.updateFlight(flightEntity);
            if (result <= 0){
                //如果修改失败，则跳转(转发)到 error.jsp 页面
                req.setAttribute("errorMsg", "修改失败");
                req.getRequestDispatcher("error.jsp").forward(req, resp);
            }
            //如果修改成功
            req.setAttribute("phone", phone);
            req.getRequestDispatcher("showFlight").forward(req, resp);
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}*/
